package main

import (
	"HelloWorld/internal"
	"HelloWorld/store"
	"HelloWorld/store/factory"
	"fmt"
)

func main() {
	fmt.Println("++++++++++++++++++++++++++++++++++")
	mytest.IterateString()
	fmt.Println("++++++++++++++++++++++++++++++++++")
	mytest.PrintArray()
	fmt.Println("++++++++++++++++++++++++++++++++++")
	mytest.RewriteArray()
	fmt.Println("++++++++++++++++++++++++++++++++++")
	mytest.RewriteArrayUseSlice()
	fmt.Println("++++++++++++++++++++++++++++++++++")
	mytest.CopyArraySlice()
	fmt.Println("++++++++++++++++++++++++++++++++++")
	mytest.CallMap()
	fmt.Println("++++++++++++++++++++++++++++++++++")
	mytest.ForFlow()
	fmt.Println("++++++++++++++++++++++++++++++++++")
	mytest.CallAdd()
	fmt.Println("++++++++++++++++++++++++++++++++++")
	mytest.SumAll(1, 2, 3, 4, 5)
	dataSlice := []int{6, 7, 8, 9, 10}
	mytest.SumAll(dataSlice...)
	dataSlice = append(dataSlice, 1, 2, 3, 4, 5)
	mytest.SumAll(dataSlice...)
	fmt.Println("++++++++++++++++++++++++++++++++++")
	mytest.PrintValues(42, "Hello", 3.14, true, []int{1, 2, 3})
	fmt.Println("++++++++++++++++++++++++++++++++++")
	c := mytest.AnonymousFunc()
	fmt.Println(c())
	fmt.Println(c())
	fmt.Println(c())
	fmt.Println("++++++++++++++++++++++++++++++++++")
	mytest.CallSortApplesWeight()
	fmt.Println("++++++++++++++++++++++++++++++++++")
	mytest.CallDoSomething()
	fmt.Println("++++++++++++++++++++++++++++++++++")
	_, err := mytest.ReadFile("test.txt")
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println("++++++++++++++++++++++++++++++++++")
	mytest.CallMayPanic()
	fmt.Println("++++++++++++++++++++++++++++++++++")

	p := mytest.NewPair(1, 2)
	fmt.Println(p.GetFirst(), p.GetSecond())

	fmt.Println(p.GetFirst(), p.GetSecond())

	fmt.Println("+++++++++++++++++++++++++++++++++++")
	mytest.TestDog()
	fmt.Println("+++++++++++++++++++++++++++++++++++")
	a := mytest.Integer(1)
	fmt.Println(a.Less(2))
	fmt.Println(a.Add(1))

	//检查type Integer 是否实现了 LessAdder 接口
	//mytest.Integer定义了指针接收者 Less 和 Add 方法
	var _ mytest.LessAdder = (*mytest.Integer)(nil)
	var a1 mytest.Integer = 1
	var b1 mytest.LessAdder

	b1 = &a1
	fmt.Println(b1.Less(2))

	//检查 MyInteger 是否实现了 LessAdder 接口
	//mytest.MyInteger定义了值接收者 Less 和 Add 方法
	var _ mytest.LessAdder = mytest.MyInteger{}
	b1 = mytest.MyInteger{A: 1}
	fmt.Println(b1.Less(2))

	//检查 b1 是否是 MyInteger 类型
	if b2, ok := b1.(mytest.MyInteger); ok {
		fmt.Println(b2.Add(1))
	}

	//检查 b1 是否是 mytest.Integer 类型
	if b3, ok := b1.(*mytest.Integer); ok {
		fmt.Println(b3.Add(1))
	} else {
		fmt.Println("b1 不是 *mytest.Integer 类型")
	}

	//询问接口指向对象实例的类型，并执行相应的操作
	var b4 mytest.LessAdder
	switch v := b4.(type) {
	case mytest.MyInteger:
		fmt.Println(v.Add(1))
	case *mytest.Integer:
		fmt.Println(v.Add(1))
	default:
		fmt.Println("b4 不是 MyInteger 或 *mytest.Integer 类型")
	}

	fmt.Println("+++++++++++++++++++++++++++++++++++")
	var p1 store.Store
	p1, _ = factory.Get("mem")
	err1 := p1.Create(&store.Book{ID: "1", Name: "Go语言基础", Authors: []string{"张三"}, Press: "Packt"})
	if err1 != nil {
		return
	}
	bk, err1 := p1.Get("1")
	fmt.Println(bk.ID)
	fmt.Println(bk.Name)

	err1 = p1.Create(&store.Book{ID: "2", Name: "Go语言实战", Authors: []string{"李四"}, Press: "Packt"})
	if err1 != nil {
		return
	}

	bk2, err1 := p1.Get("2")
	fmt.Println(bk2.ID)
	fmt.Println(bk2.Name)

}
